package com.example.kingdee.controller;

import com.example.kingdee.KingdeeCreate.dto.CreateInDto;
import com.example.kingdee.KingdeeCreate.impl.CreateSalBillImpl;
import com.example.kingdee.common.AjaxResult;
import com.example.kingdee.common.StringUtils;
import com.example.kingdee.kingdeeBridge.common.RequestResult;
import com.example.kingdee.kingdeeBridge.dto.BillWriteInDto;
import com.example.kingdee.service.KingdeeService;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * 金蝶接口调用控制层
 */
@RestController
@RequestMapping("//kingdee")
public class KingdeeController {

    @Autowired
    private KingdeeService kingdeeService;
    @Autowired
    private CreateSalBillImpl createSalBill;

    //单据写入通用接口（下推单据——>修改目标单据模式）
    @PostMapping("/billWriteIn")
    public AjaxResult billWriteIn(@RequestBody BillWriteInDto billWriteInDto){
        HashMap<String, Object> result = kingdeeService.billWriteIn(billWriteInDto);
        if (StringUtils.isNull(result)) {
            result = new HashMap<>();
        }
        return AjaxResult.success(result);
    }

    //创建单据（直接创建目标单据模式）
    @PostMapping("/billCreateIn")
    public AjaxResult billCreateIn(@RequestBody CreateInDto createInDto){
        HashMap<String, Object> result = kingdeeService.billCreateIn(createInDto);
        if (StringUtils.isNull(result)) {
            result = new HashMap<>();
        }
        return AjaxResult.success(result);
    }

    //创建单据（直接创建目标单据模式）
    @PostMapping("/createSalBill")
    public AjaxResult createSalBill(@RequestBody CreateInDto createInDto){
        createSalBill.editCreateInDto(createInDto);
        return AjaxResult.success();
    }

    //数据校验（直接创建目标单据模式）
    @PostMapping("/verifySalBill")
    public AjaxResult verifySalBill(@RequestBody CreateInDto createInDto){
        createSalBill.verifySalBill(createInDto);
        return AjaxResult.success();
    }

//    @PostMapping("/ppBomTest")
//    public AjaxResult ppBomTest(@RequestBody CreateInDto createInDto){
//        List<CreateInDto> createInDtoList = createSalBill.editCreateInDto(createInDto);
//        for (CreateInDto inDto : createInDtoList) {
//            kingdeeService.billCreateIn(inDto);
//        }
//        return AjaxResult.success();
//    }
}
